﻿namespace Smart.Service
{
    using Smart.Utils.App;
    using Smart.Utils.Security2;
    using Smart.Utils.System2;
    using System;

    internal static class MyRegister
    {
        public static string GenID()
        {
            string systemInfo = SystemInfoHelper.GetSystemInfo(SystemInfoHelper.GetSoftware(MyAssembly.AssemblyTitle));
            string str3 = "";
            systemInfo = new MyEncryption().MD5Encrypt(systemInfo);
            return (((((str3 + systemInfo.Substring(0, 8)) + "-" + systemInfo.Substring(9, 4)) + "-" + systemInfo.Substring(14, 4)) + "-" + systemInfo.Substring(0x13, 4)) + "-" + systemInfo.Substring(0x18));
        }

        public static string[] MakeCode(string Key)
        {
            string[] strArray = new string[] { Key, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
            MyEncryption encryption = new MyEncryption();
            string phrase = MyEncryption.Encrypt(MyEncryption.Encrypt(Key + MyEncryption.InverseString(Key) + Key.Length.ToString(), Key, true), Key, true);
            phrase = encryption.SHA512Encrypt(phrase);
            strArray[3] = phrase.Substring(6, 5);
            strArray[4] = phrase.Substring(0x12, 5);
            strArray[5] = phrase.Substring(0x18, 5);
            strArray[6] = phrase.Substring(0x11, 5);
            strArray[7] = phrase.Substring(0x20, 5);
            return strArray;
        }

        public static string Register(string FileName, string Key, string[] vData)
        {
            string[] data = MakeCode(Key);
            data[8] = DateTime.Now.Ticks.ToString();
            data[9] = DateTime.Now.Ticks.ToString();
            data[10] = "50";
            data[11] = "1";
            data[12] = MyAssembly.AssemblyTitle;
            data[13] = "30";
            data[14] = "0";
            data[15] = "0";
            string str = "M\x00e3 số đăng k\x00fd sai.";
            bool flag = true;
            if (data[3] != vData[3])
            {
                str = "M\x00e3 số đăng k\x00fd sai.";
                flag = false;
            }
            else if (data[4] != vData[4])
            {
                str = "M\x00e3 số đăng k\x00fd sai.";
                if (flag)
                {
                    flag = false;
                }
            }
            if (data[5] != vData[5])
            {
                str = "M\x00e3 số đăng k\x00fd sai.";
                if (flag)
                {
                    flag = false;
                }
            }
            if (data[6] != vData[6])
            {
                str = "M\x00e3 số đăng k\x00fd sai.";
                if (flag)
                {
                    flag = false;
                }
            }
            if (data[7] != vData[7])
            {
                str = "M\x00e3 số đăng k\x00fd sai.";
                if (flag)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                str = "OK";
                FileReadWrite.WriteFile(FileName, data, Key);
            }
            return str;
        }
    }
}

